package ian.swing;

import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.*;


public class Entrance extends JFrame implements MouseListener{

	private String user = "";
	private JButton homeBtn = new JButton("Home");
	
	public Entrance()
	{
		super();
		this.setTitle("Log in");
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setSize(700,500);
		this.setVisible(true);
		this.homeBtn.addMouseListener(this);
		returnLogin();
	}
	
	public void returnLogin()
	{
		Container contentPane = getContentPane();
		contentPane.setLayout(new FlowLayout());
		LogInPanel login = new LogInPanel();
		contentPane.add(login);
		login.setFrame(this);
		refresh();
	}
	
	private void refresh()
	{
		this.setVisible(false);
		this.setVisible(true);
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Entrance();
	}

	@Override
	public void mouseClicked(MouseEvent arg0) {
		// TODO Auto-generated method stub
		if(((JButton)arg0.getComponent()).getText().equals("Log in")){
			this.user = ((LogInPanel)arg0.getComponent().getParent()).getText();
			this.getContentPane().remove((LogInPanel)arg0.getComponent().getParent());
			this.getContentPane().setLayout(new BorderLayout());
			ControlPanel cp = new ControlPanel(user);
			this.getContentPane().add(homeBtn,BorderLayout.NORTH);
			this.getContentPane().add(cp,BorderLayout.CENTER);
			this.refresh();
		}
		if(((JButton)arg0.getComponent()).getText().equals("Home")){
			this.user = "";
			getContentPane().removeAll();
			returnLogin();
			this.refresh();
		}
	}
	public void mouseEntered(MouseEvent arg0) {
	}
	public void mouseExited(MouseEvent arg0) {
	}
	public void mousePressed(MouseEvent arg0) {
	}
	public void mouseReleased(MouseEvent arg0) {
	}
}
